package opdracht4;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class TreeTest 
{
	protected SearchTree<Integer, String> list;
	
	@Test
	public void fillEmpty()
	{
		list = new SearchTree<Integer, String>();
		assertEquals("_", list.toString());
	}
	@Test
	public void testAdd_OneElement()
	{
		fillEmpty();
		list.put(5, "Alfa");
		assertEquals("(_, (5, Alfa), _)", list.toString());
	}
	@Test
	public void testAdd_ManyElements()
	{
		testAdd_OneElement();
		list.put(4, "Beta");
		list.put(3, "Gamma");
		list.put(7, "Elipson");
		list.put(8, "Wau");
	}
	@Test
	public void testAdd_ManyElementsCorrect()
	{
		testAdd_ManyElements();
		assertEquals("(((_, (3, Gamma), _), (4, Beta), _), (5, Alfa), (_, (7, Elipson), (_, (8, Wau), _)))", list.toString());
	}
	@Test
	public void testAdd_AddSevenToRight()
	{
		fillEmpty();
		list.put(1, "Alfa");
		list.put(2, "Beta");
		list.put(3, "Gamma");
		list.put(4, "Elipson");
		list.put(5, "Wau");
		list.put(6, "Theta");
		list.put(7, "Omega");
	}
	@Test
	public void testAdd_AddSevenToRightCorrect()
	{
		testAdd_AddSevenToRight();
		assertEquals("(_, (1, Alfa), (_, (2, Beta), (_, (3, Gamma), (_, (4, Elipson), (_, (5, Wau), (_, (6, Theta), (_, (7, Omega), _)))))))", list.toString());
	}
	@Test
	public void testAdd_AddSevenToLeft()
	{
		fillEmpty();
		list.put(7, "Alfa");
		list.put(6, "Beta");
		list.put(5, "Gamma");
		list.put(4, "Elipson");
		list.put(3, "Wau");  
		list.put(2, "Theta");
		list.put(1, "Kappa");
	}
	@Test
	public void testAdd_AddSevenToLeftCorrect()
	{
		testAdd_AddSevenToLeft();
		assertEquals("(((((((_, (1, Kappa), _), (2, Theta), _), (3, Wau), _), (4, Elipson), _), (5, Gamma), _), (6, Beta), _), (7, Alfa), _)", list.toString());
	}
	@Test
	public void testSize_Empty()
	{
		fillEmpty();
		assertEquals(0, list.size());
	}
	@Test
	public void testSize_OneElement()
	{
		testAdd_OneElement();
		assertEquals(1, list.size());
	}
	@Test
	public void testSize_ManyElements()
	{
		testAdd_ManyElements();
		assertEquals(5, list.size());
	}
	@Test
	public void testHeight_Empty()
	{
		fillEmpty();
		assertEquals(0, list.height());
	}
	@Test
	public void testHeight_OneElement()
	{
		testAdd_OneElement();
		assertEquals(1, list.height());
	}
	@Test
	public void testHeight_ManyElements()
	{
		testAdd_ManyElements();
		assertEquals(3, list.height());
	}
	public void testGet_OneElement()
	{
		testAdd_OneElement();
		assertEquals("Alfa", list.get(5));
	}
	@Test
	public void testAdd_DoubleElement()
	{
		testAdd_ManyElements();
		list.put(3, "Gamma");
		assertEquals("(((_, (3, Gamma), _), (4, Beta), _), (5, Alfa), (_, (7, Elipson), (_, (8, Wau), _)))", list.toString());
	}
	@Test
	public void testAdd_DoubleElement_END()
	{
		testAdd_ManyElements();
		list.put(5, "Alfa");
		assertEquals("(((_, (3, Gamma), _), (4, Beta), _), (5, Alfa), (_, (7, Elipson), (_, (8, Wau), _)))", list.toString());
	}
	@Test
	public void testGet_ManyElements()
	{
		testAdd_ManyElements();
		assertEquals("Wau", list.get(8));
	}
	@Test
	public void testGet_ManyElements_WRONG()
	{
		testAdd_ManyElements();
		assertEquals(null, list.get(9));
	}
	@Test
	public void testGet_ManyElements_WRONG2()
	{
		testAdd_ManyElements();
		assertEquals(null, list.get(2));
	}
	@Test
	public void testContains_Empty()
	{
		fillEmpty();
		assertFalse(list.contains("Alfa"));
	}
	@Test
	public void testContains_OneElement()
	{
		testAdd_OneElement();
		assertTrue(list.contains("Alfa"));
	}
	@Test
	public void testContains_ManyElement_TRUE()
	{
		testAdd_ManyElements();
		assertTrue(list.contains("Elipson"));
	}
	@Test
	public void testContains_ManyElement_FALSE()
	{
		testAdd_ManyElements();
		assertFalse(list.contains("Omega"));
	}
	@Test
	public void testContainsKey_Empty()
	{
		fillEmpty();
		assertFalse(list.containsKey(5));
	}
	@Test
	public void testContainsKey_OneElement()
	{
		testAdd_OneElement();
		assertTrue(list.containsKey(5));
	}
	@Test
	public void testContainsKey_ManyElements_TRUE()
	{
		testAdd_ManyElements();
		assertTrue(list.containsKey(7));
	}
	@Test
	public void testContainsKey_ManyElements_FALSE()
	{
		testAdd_ManyElements();
		assertFalse(list.containsKey(0));
	}
	@Test
	public void testRemove_Empty()
	{
		fillEmpty();
		list.remove(5);
		assertTrue(list.isEmpty());
	}
	@Test
	public void testRemove_OneElement()
	{
		testAdd_OneElement();
		list.remove(5);
		assertEquals("_", list.toString());
	}
	@Test
	public void testRemove_ManyElement()
	{
		testAdd_ManyElements();
		list.remove(7);
		assertEquals("(((_, (3, Gamma), _), (4, Beta), _), (5, Alfa), (_, (8, Wau), _))", list.toString());
	}
	@Test
	public void testRemove_ManyElement2()
	{
		testAdd_ManyElements();
		list.remove(5);
		assertEquals("((_, (3, Gamma), _), (4, Beta), (_, (7, Elipson), (_, (8, Wau), _)))", list.toString());
	}
	@Test
	public void testRemove_ManyElements_WRONG()
	{
		testAdd_ManyElements();
		list.remove(10);
		assertEquals("(((_, (3, Gamma), _), (4, Beta), _), (5, Alfa), (_, (7, Elipson), (_, (8, Wau), _)))", list.toString());
	}
}
